﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Security;
using University.Workshop.Model;
using University.Workshop.DataAccess;
using University.Workshop.Business;
using System.Web.UI;

namespace University.Workshop.WebApp
{
    /// <summary>
    /// Summary description for UserRateHandler
    /// </summary>
    public class UserRateHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            Rating rate = new Rating();

            string Rate = context.Request.QueryString["Rate"];
            string userMail = context.Request.QueryString["userName"];
            string feedBack = context.Request.QueryString["feedBack"];
           
            string user = context.User.Identity.Name;

            rate.ProductId = UserDataAccess.GetUserByEmail(userMail).Id;
            rate.Rate = int.Parse(Rate);
            rate.UserId = UserDataAccess.GetUserByEmail(user).Id;
            rate.Date = DateTime.Now;
            rate.Comment = feedBack;
            
            if (true)
            {
                rate = RatingDataAccess.InsertUserRating(rate);
                context.Response.Write("<script>alert('User Feedback Registered!');</script>");
            }
            context.Response.Write("<script>window.location.href = 'PaypalSuccess.aspx';</script>");
        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }
    }
}